package com.haotian.zip.web;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

/**
 * 
 * 如果请求消息中包含gzip压缩数据，则进行解压
 * 
 * 调用者需继承本类
 * 
 * 配置注解或xml 
 * 
 * 注解：@WebFilter(filterName = "gzipFilter", urlPatterns = "/*")
 * 
 * @ClassName: _GzipFilter
 * @Description: TODO
 * @author: mr.zhurunhua
 * @date: 2017年6月16日 下午4:28:34
 */

public class _GzipFilterBasic implements Filter {

	public static final Logger LOGGER = Logger.getLogger(_GzipFilterBasic.class);

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		LOGGER.info("---------------init _GzipFilterBasic----------------");
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		chain.doFilter(new GzipRequestWrapper((HttpServletRequest)request),response);
	}

	@Override
	public void destroy() {
		LOGGER.info("---------------destroy _GzipFilterBasic----------------");
	}

}